﻿#region License

// PentaBiz - Sustainable Software Development Framework Copyright (C) 2013 Zoltán Csizmazia
// 
// This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
// 
// This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
// 
// You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 

#endregion

using System;
using System.Collections.Generic;
using System.Data.Services.Providers;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using PentaBiz.Cloud.Services.CommandService;
using PentaBiz.Cloud.Services.QueryService.OData;
using PentaBiz.Cloud.Services.Testing.SampleContext;
using PentaBiz.Diagnostics;

namespace PentaBiz.Cloud.Services.Testing
{
    [TestClass]
    public class UnitTestODataService
    {
        [TestMethod]
        [TestCategory("ODataService")]
        public void TestODataService()
        {
            var s = new ODataService<TestMetaDbQueryContext>();
            Assert.IsNotNull(s, "OdataService must not be initialized");

            var wr = s.GetLeakMonitor();

            s = null;
            wr.AssertInstanceIsDead();
        }

        [TestMethod]
        [TestCategory("ODataService")]
        public void TestGetIDataServiceMetadataProvider()
        {
            var s = new ODataService<TestMetaDbQueryContext>();
            Assert.IsNotNull(s, "OdataService must not be initialized");

            var wr = s.GetLeakMonitor();

            var o = (IDataServiceMetadataProvider) s.GetService(typeof (IDataServiceMetadataProvider));
            Assert.IsNotNull(o, "IDataServiceMetadataProvider must be initialized by service");

            o = null;
            s = null;

            wr.AssertInstanceIsDead();
        }

        [TestMethod]
        [TestCategory("ODataService")]
        public void TestGetIDataServiceQueryProvider()
        {
            var s = new ODataService<TestMetaDbQueryContext>();
            Assert.IsNotNull(s, "OdataService must not be initialized");

            var wr = s.GetLeakMonitor();

            var o = (IDataServiceQueryProvider) s.GetService(typeof (IDataServiceQueryProvider));
            Assert.IsNotNull(o, "IDataServiceQueryProvider must be initialized by service");

            wr.AssertInstanceIsDead();
        }
    }

    [TestClass]
    public class UnitTestODataServiceQueryProvider
    {
        [TestMethod]
        [TestCategory("ODataServiceQueryProvider")]
        public void TestCurrentDataSourceIsNotNull()
        {
            var s = new ODataService<TestMetaDbQueryContext>();
            Assert.IsNotNull(s, "OdataService must not be initialized");

            var wr = s.GetLeakMonitor();

            var o = (IDataServiceQueryProvider) s.GetService(typeof (IDataServiceQueryProvider));
            Assert.IsNotNull(o, "IDataServiceQueryProvider must be initialized by service");

            object d = o.CurrentDataSource;
            Assert.IsNotNull(d, "CurrentDataSource must not be null");

            d = null;
            o = null;
            s = null;
            wr.AssertInstanceIsDead();
        }
    }
}